package 我的Java学习_算法基础.day_04;

public class _061_将0所在的行列清零 {
    public static void main(String[] args) {
        int[][] a ={
                {1,2,3,4,100},
                {5,6,7,0,101},
                {9,0,11,12,102},
                {13,14,15,16,103},
                {104,105,106,107,103}
        };

        for (int[] e:a
             ) {
            for (int i:e
                 ) {
                System.out.print(i+"\t");
            }
            System.out.println();
        }
        clear(a);
        System.out.println();
        for (int[] e:a
        ) {
            for (int i:e
            ) {
                System.out.print(i+"\t");
            }
            System.out.println();
        }
    }
    private static void clear(int[][] array){
        int r = array.length;
        int c = array[0].length;
        int[] rowRecord = new int[r];
        int[] colRecord = new int[c];
        for (int i = 0; i < r; i++) {
            for(int j = 0;j<c;j++){
                if(array[i][j]==0){
                    rowRecord[i] = 1;
                    colRecord[j] = 1;
                }
            }

        }
        for(int i = 0;i<r;i++){
            for(int j = 0;j<c;j++){
                if(rowRecord[i]==1||colRecord[j]==1){
                    array[i][j]=0;
                }
            }
        }
    }
}
